package com.example.demo.controller;

import com.example.demo.http.Result;
import com.example.demo.service.AsyncService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

@RestController
@Slf4j
public class AsyncController {

    @Autowired
    private AsyncService asyncService;



    @RequestMapping("/asyncNoResult")
    public Result<String> addMemberAndEmail(){
      log.info("1");
      String result=asyncService.addMemberActionAndEmail();
      log.info("4");
      return Result.createSuccesful("返回成功");
    }

    @RequestMapping("/asyncForResult")
    public Result<String> addMemberForResult() throws Exception{
        log.info("1");
        Future<String> result = asyncService.sendDataWithResult();
        log.info("4");
        return Result.createSuccesful(result.get(10, TimeUnit.SECONDS));
    }


}
